import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../providers/home_provider.dart';
import '../../providers/fishing_provider.dart';
import '../../providers/location_weather_provider.dart';
import '../../providers/community_provider.dart';
import '../../providers/version_provider.dart';
import 'package:go_router/go_router.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  late PageController _noticeController;
  late ScrollController _scrollController;
  int _currentNoticeIndex = 0;

  @override
  void initState() {
    super.initState();
    _noticeController = PageController();
    _scrollController = ScrollController();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      context.read<HomeProvider>().loadNotices();
      context.read<FishingProvider>().loadFishingSpots();
      context.read<LocationWeatherProvider>().initializeLocationAndWeather();
      context.read<CommunityProvider>().loadHotPosts();
      _startNoticeAutoPlay();
      
      // 用户登录后进入首页时自动检查版本更新
      _checkVersionUpdate();
    });
  }

  @override
  void dispose() {
    _noticeController.dispose();
    _scrollController.dispose();
    super.dispose();
  }

  void _startNoticeAutoPlay() {
    Future.delayed(const Duration(seconds: 4), () {
      if (mounted && _noticeController.hasClients) {
        final provider = context.read<HomeProvider>();
        if (provider.notices.isNotEmpty) {
          _currentNoticeIndex = (_currentNoticeIndex + 1) % provider.notices.length;
          _noticeController.animateToPage(
            _currentNoticeIndex,
            duration: const Duration(milliseconds: 300),
            curve: Curves.easeInOut,
          );
        }
        _startNoticeAutoPlay();
      }
    });
  }

  /// 检查版本更新
  void _checkVersionUpdate() {
    // 延迟2秒后检查，确保首页加载完成
    Future.delayed(const Duration(seconds: 2), () {
      if (mounted) {
        try {
          // 强制检查，忽略时间限制
          context.read<VersionProvider>().checkUpdate(forceCheck: true);
        } catch (e) {
          print('版本检查失败: $e');
        }
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true, // 推荐开启
      backgroundColor: Colors.white,
      body: CustomScrollView(
        controller: _scrollController,
        physics: const BouncingScrollPhysics(),
        slivers: [
          // 自定义AppBar
          _buildSliverAppBar(),
          
          // 主要内容
          SliverToBoxAdapter(
            child: Column(
              children: [
                // 状态栏
                _buildStatusBar(),
                
                // 最新通知
                _buildNoticeSection(),
                
                // 快捷功能
                _buildQuickActions(),
                
                // 数据统计
                _buildDataStats(),
                
                // 推荐钓场
                _buildRecommendedFishing(),
                
                const SizedBox(height: 80),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSliverAppBar() {
    return SliverAppBar(
      floating: false,
      pinned: true,
      snap: false,
      stretch: false,
      backgroundColor: Colors.blue[600],
      flexibleSpace: FlexibleSpaceBar(
        title: const Text(
          '鱼乐无限',
          style: TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.w600,
          ),
        ),
        background: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
              colors: [
                Colors.blue[600]!,
                Colors.blue[800]!,
              ],
            ),
          ),
        ),
      ),
      actions: [
        IconButton(
          icon: const Icon(Icons.notifications_outlined, color: Colors.white),
          onPressed: () {
            context.push('/notifications');
          },
        ),
      ],
    );
  }

  Widget _buildStatusBar() {
    return Container(
      margin: const EdgeInsets.all(16),
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withAlpha((0.05 * 255).round()),
            blurRadius: 10,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Consumer<LocationWeatherProvider>(
        builder: (context, locationWeatherProvider, child) {
          return Row(
            children: [
              Icon(Icons.location_on, color: Colors.blue[600], size: 20),
              const SizedBox(width: 8),
              Expanded(
                child: Text(
                  '当前位置：${locationWeatherProvider.currentAddress}',
                  style: const TextStyle(fontSize: 14, color: Colors.black87),
                  overflow: TextOverflow.ellipsis,
                ),
              ),
              const SizedBox(width: 8),
              if (locationWeatherProvider.isLoading)
                SizedBox(
                  width: 16,
                  height: 16,
                  child: CircularProgressIndicator(
                    strokeWidth: 2,
                    valueColor: AlwaysStoppedAnimation<Color>(Colors.orange[600]!),
                  ),
                )
              else ...[
                Text(
                  locationWeatherProvider.weatherIcon,
                  style: const TextStyle(fontSize: 16),
                ),
                const SizedBox(width: 4),
                Text(
                  '${locationWeatherProvider.weatherDescription} ${locationWeatherProvider.temperature}°C',
                  style: const TextStyle(fontSize: 14, color: Colors.black87),
                ),
              ],
              const SizedBox(width: 8),
              GestureDetector(
                onTap: () {
                  locationWeatherProvider.refreshLocationAndWeather();
                },
                child: Icon(
                  Icons.refresh,
                  color: Colors.grey[600],
                  size: 18,
                ),
              ),
            ],
          );
        },
      ),
    );
  }

  Widget _buildQuickActions() {
    final actions = [
      // {'icon': Icons.pool, 'title': '附近钓场', 'color': Colors.blue,'page':'/fishing'},
      // {'icon': Icons.event, 'title': '预约钓位', 'color': Colors.green,'page':'/fishing'},
      // {'icon': Icons.people, 'title': '钓友圈', 'color': Colors.orange,'page':'/community'},
      {'icon': Icons.book_online, 'title': '我的预约', 'color': Colors.purple,'page':'/prebook'},
      {'icon': Icons.assessment, 'title': '钓况报告', 'color': Colors.teal,'page':'/fishing-report'},
      {'icon': Icons.school, 'title': '钓技学堂', 'color': Colors.indigo,'page':'/technique'},
      {'icon': Icons.emoji_events, 'title': '钓王榜', 'color': Colors.red,'page':'/fishing-king'},
      // {'icon': Icons.person, 'title': '我的信息', 'color': Colors.amber,'page':'/profile'},
    ];

    return Container(
      margin: const EdgeInsets.all(16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题在卡片外面
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 4),
            child: Row(
              children: [
                Icon(Icons.apps, color: Colors.blue[600], size: 20),
                const SizedBox(width: 8),
                const Text(
                  '快捷服务',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                    color: Colors.black87,
                  ),
                ),
              ],
            ),
          ),
          const SizedBox(height: 12),
          // 卡片内容
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(16),
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withAlpha((0.05 * 255).round()),
                  blurRadius: 10,
                  offset: const Offset(0, 2),
                ),
              ],
            ),
            child: GridView.builder(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              padding: EdgeInsets.zero,
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 4,
                mainAxisSpacing: 12,
                crossAxisSpacing: 8,
                childAspectRatio: 0.9,
              ),
              itemCount: actions.length,
              itemBuilder: (context, index) {
                final action = actions[index];
                return _buildQuickActionItem(
                  action['icon'] as IconData,
                  action['title'] as String,
                  action['color'] as Color,
                  () {
                    final page = action['page'] as String;
                    // 底部导航栏的页面使用go，其他页面使用push
                    if (page == '/fishing' || page == '/community' || page == '/profile') {
                      context.go(page);
                    } else {
                      context.push(page);
                    }
                  },
                );
              },
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildDataStats() {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 4),
            child: Row(
              children: [
                Icon(Icons.whatshot, color: Colors.orange[600], size: 20),
                const SizedBox(width: 8),
                const Text(
                  '钓友圈热门',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                    color: Colors.black87,
                  ),
                ),
                const Spacer(),
                TextButton(
                  onPressed: () {
                    context.go('/community');
                  },
                  child: Text(
                    '查看更多',
                    style: TextStyle(color: Colors.blue[600]),
                  ),
                ),
              ],
            ),
          ),
          const SizedBox(height: 12),
          Container(
            height: 120,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(16),
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withAlpha((0.05 * 255).round()),
                  blurRadius: 10,
                  offset: const Offset(0, 2),
                ),
              ],
            ),
            child: Consumer<CommunityProvider>(
              builder: (context, communityProvider, child) {
                // 暂时注释掉主页状态日志
                
                if (communityProvider.isLoadingHotPosts) {
                  return const Center(
                    child: CircularProgressIndicator(),
                  );
                }

                if (communityProvider.hotPosts.isEmpty) {
                  return Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        const Text(
                          '暂无热门帖子',
                          style: TextStyle(color: Colors.grey, fontSize: 14),
                        ),
                        const SizedBox(height: 4),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            TextButton(
                              onPressed: () {
                                // 重新加载热门帖子
                                context.read<CommunityProvider>().loadHotPosts();
                              },
                              style: TextButton.styleFrom(
                                padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
                                minimumSize: const Size(0, 32),
                              ),
                              child: const Text('重试', style: TextStyle(fontSize: 12)),
                            ),
                            const SizedBox(width: 8),
                            TextButton(
                              onPressed: () async {
                                // 直接测试API调用
                                try {
                                  final communityService = context.read<CommunityProvider>();
                                  await communityService.loadHotPosts();
                                } catch (e) {
                                }
                              },
                              style: TextButton.styleFrom(
                                padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
                                minimumSize: const Size(0, 32),
                              ),
                              child: const Text('调试API', style: TextStyle(fontSize: 12)),
                            ),
                          ],
                        ),
                      ],
                    ),
                  );
                }

                // 只显示前3个热门帖子
                final displayPosts = communityProvider.hotPosts.take(3).toList();

                return ListView.separated(
                  padding: const EdgeInsets.all(16),
                  itemCount: displayPosts.length,
                  separatorBuilder: (context, index) => const Divider(height: 16),
                  itemBuilder: (context, index) {
                    final post = displayPosts[index];
                    return GestureDetector(
                      onTap: () {
                        // 跳转到帖子详情页
                        context.push('/community/${post.id}', extra: post);
                      },
                      child: Row(
                        children: [
                          Container(
                            width: 4,
                            height: 20,
                            decoration: BoxDecoration(
                              color: Colors.orange[600],
                              borderRadius: BorderRadius.circular(2),
                            ),
                          ),
                          const SizedBox(width: 12),
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  post.title,
                                  style: const TextStyle(
                                    fontSize: 14,
                                    fontWeight: FontWeight.w600,
                                    color: Colors.black87,
                                  ),
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                ),
                                const SizedBox(height: 4),
                                Row(
                                  children: [
                                    Text(
                                      post.authorName,
                                      style: TextStyle(
                                        fontSize: 12,
                                        color: Colors.grey[600],
                                      ),
                                    ),
                                    const Spacer(),
                                    Icon(
                                      Icons.thumb_up_outlined,
                                      size: 12,
                                      color: Colors.grey[600],
                                    ),
                                    const SizedBox(width: 4),
                                    Text(
                                      '${post.likeCount}',
                                      style: TextStyle(
                                        fontSize: 12,
                                        color: Colors.grey[600],
                                      ),
                                    ),
                                    const SizedBox(width: 12),
                                    Icon(
                                      Icons.visibility_outlined,
                                      size: 12,
                                      color: Colors.grey[600],
                                    ),
                                    const SizedBox(width: 4),
                                    Text(
                                      '${post.readCount}',
                                      style: TextStyle(
                                        fontSize: 12,
                                        color: Colors.grey[600],
                                      ),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                );
              },
            ),
          ),
        ],
      ),
    );
  }


  Widget _buildRecommendedFishing() {
    return Container(
      margin: const EdgeInsets.all(16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 4),
            child: Row(
              children: [
                Icon(Icons.pool, color: Colors.blue[600], size: 20),
                const SizedBox(width: 8),
                const Text(
                  '推荐钓场',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                    color: Colors.black87,
                  ),
                ),
                const Spacer(),
                TextButton(
                  onPressed: () => context.go('/fishing'),
                  child: Text(
                    '查看更多',
                    style: TextStyle(color: Colors.blue[600]),
                  ),
                ),
              ],
            ),
          ),
          const SizedBox(height: 12),
          Consumer<FishingProvider>(
            builder: (context, fishingProvider, child) {
              if (fishingProvider.isLoading) {
                return Container(
                  height: 200,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(16),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withAlpha((0.05 * 255).round()),
                        blurRadius: 10,
                        offset: const Offset(0, 2),
                      ),
                    ],
                  ),
                  child: const Center(
                    child: CircularProgressIndicator(),
                  ),
                );
              }

              if (fishingProvider.recommendedSpots.isEmpty) {
                return Container(
                  height: 200,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(16),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withAlpha((0.05 * 255).round()),
                        blurRadius: 10,
                        offset: const Offset(0, 2),
                      ),
                    ],
                  ),
                  child: const Center(
                    child: Text(
                      '暂无推荐钓场',
                      style: TextStyle(color: Colors.grey),
                    ),
                  ),
                );
              }

              return SizedBox(
                height: 200,
                child: ListView.builder(
                  scrollDirection: Axis.horizontal,
                  physics: const BouncingScrollPhysics(),
                  padding: const EdgeInsets.symmetric(horizontal: 4),
                  itemCount: fishingProvider.recommendedSpots.length,
                  itemBuilder: (context, index) {
                    final spot = fishingProvider.recommendedSpots[index];
                    return GestureDetector(
                      onTap: () {
                        context.push('/fishing/${spot.id}');
                      },
                      child: Container(
                        width: 160,
                        margin: const EdgeInsets.only(right: 12),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(12),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.black.withAlpha((0.05 * 255).round()),
                              blurRadius: 10,
                              offset: const Offset(0, 2),
                            ),
                          ],
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            ClipRRect(
                              borderRadius: const BorderRadius.vertical(
                                top: Radius.circular(12),
                              ),
                              child: Container(
                                height: 100,
                                width: double.infinity,
                                child: spot.images.isNotEmpty
                                    ? Image.network(
                                        spot.images.first,
                                        fit: BoxFit.cover,
                                        errorBuilder: (context, error, stackTrace) {
                                          return _buildDefaultSpotImage();
                                        },
                                      )
                                    : _buildDefaultSpotImage(),
                              ),
                            ),
                            Padding(
                              padding: const EdgeInsets.all(12),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    spot.name,
                                    style: const TextStyle(
                                      fontSize: 14,
                                      fontWeight: FontWeight.w600,
                                    ),
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                  ),
                                  const SizedBox(height: 4),
                                  Row(
                                    children: [
                                      Icon(
                                        Icons.location_on,
                                        size: 12,
                                        color: Colors.grey[600],
                                      ),
                                      const SizedBox(width: 4),
                                      Expanded(
                                        child: Text(
                                          '距离 ${spot.distance.toStringAsFixed(1)}km',
                                          style: TextStyle(
                                            fontSize: 12,
                                            color: Colors.grey[600],
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                  const SizedBox(height: 8),
                                  Row(
                                    children: [
                                      Icon(
                                        Icons.star,
                                        size: 12,
                                        color: Colors.amber[600],
                                      ),
                                      const SizedBox(width: 4),
                                      Text(
                                        spot.rating.toStringAsFixed(1),
                                        style: const TextStyle(fontSize: 12),
                                      ),
                                      const SizedBox(width: 8),
                                      Text(
                                        '(${spot.reviewCount})',
                                        style: TextStyle(
                                          fontSize: 10,
                                          color: Colors.grey[600],
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                ),
              );
            },
          ),
        ],
      ),
    );
  }

  Widget _buildDefaultSpotImage() {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Colors.blue[300]!, Colors.blue[500]!],
        ),
      ),
      child: const Center(
        child: Icon(
          Icons.pool,
          color: Colors.white,
          size: 40,
        ),
      ),
    );
  }

  Widget _buildNoticeSection() {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 4),
            child: Row(
              children: [
                Icon(Icons.campaign, color: Colors.blue[600], size: 20),
                const SizedBox(width: 8),
                const Text(
                  '最新通知',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                    color: Colors.black87,
                  ),
                ),
              ],
            ),
          ),
          const SizedBox(height: 12),
          Consumer<HomeProvider>(
            builder: (context, provider, child) {
              if (provider.loading) {
                return Container(
                  height: 180,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(16),
                  ),
                  child: const Center(
                    child: CircularProgressIndicator(),
                  ),
                );
              }
              
              if (provider.notices.isEmpty) {
                return Container(
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(16),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withAlpha((0.05 * 255).round()),
                        blurRadius: 10,
                        offset: const Offset(0, 2),
                      ),
                    ],
                  ),
                  child: const Center(
                    child: Text(
                      '暂无通知',
                      style: TextStyle(color: Colors.grey),
                    ),
                  ),
                );
              }
              
              return SizedBox(
                height: 180,
                child: PageView.builder(
                  controller: _noticeController,
                  itemCount: provider.notices.length,
                  onPageChanged: (index) {
                    setState(() {
                      _currentNoticeIndex = index;
                    });
                  },
                  itemBuilder: (context, index) {
                    final notice = provider.notices[index];
                    return Container(
                      margin: const EdgeInsets.only(right: 8),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(16),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black.withAlpha((0.05 * 255).round()),
                            blurRadius: 10,
                            offset: const Offset(0, 2),
                          ),
                        ],
                      ),
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(16),
                        child: Stack(
                          children: [
                            // 背景图片
                            Positioned.fill(
                              child: notice.imageUrl != null && notice.imageUrl!.isNotEmpty
                                  ? Image.network(
                                      notice.imageUrl!,
                                      fit: BoxFit.cover,
                                      errorBuilder: (context, error, stackTrace) {
                                        return _buildDefaultNoticeBackground(index);
                                      },
                                    )
                                  : _buildDefaultNoticeBackground(index),
                            ),
                            // 渐变遮罩
                            Positioned.fill(
                              child: Container(
                                decoration: BoxDecoration(
                                  gradient: LinearGradient(
                                    begin: Alignment.topCenter,
                                    end: Alignment.bottomCenter,
                                    colors: [
                                      Colors.transparent,
                                      Colors.black.withAlpha((0.7 * 255).round()),
                                    ],
                                  ),
                                ),
                              ),
                            ),
                            // 内容
                            Positioned(
                              left: 16,
                              right: 16,
                              bottom: 16,
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisSize: MainAxisSize.min,
                                children: [
                                  Text(
                                    notice.title ?? '无标题',
                                    style: const TextStyle(
                                      color: Colors.white,
                                      fontSize: 16,
                                      fontWeight: FontWeight.bold,
                                    ),
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                  ),
                                  ],
                              ),
                            ),
                            // 点击效果
                            Positioned.fill(
                              child: Material(
                                color: Colors.transparent,
                                child: InkWell(
                                  borderRadius: BorderRadius.circular(16),
                                  onTap: () {
                                    // 跳转到通知详情页面，传递当前通知对象
                                    context.push('/news', extra: notice);
                                  },
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                ),
              );
            },
          ),
        ],
      ),
    );
  }

  Widget _buildDefaultNoticeBackground(int index) {
    final colors = [
      [Colors.blue[400]!, Colors.blue[600]!],
      [Colors.green[400]!, Colors.green[600]!],
      [Colors.orange[400]!, Colors.orange[600]!],
      [Colors.purple[400]!, Colors.purple[600]!],
      [Colors.teal[400]!, Colors.teal[600]!],
    ];
    
    final colorPair = colors[index % colors.length];
    
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: colorPair,
        ),
      ),
      child: Stack(
        children: [
          Positioned(
            right: -30,
            top: -30,
            child: Container(
              width: 120,
              height: 120,
              decoration: BoxDecoration(
                color: Colors.white.withAlpha((0.1 * 255).round()),
                shape: BoxShape.circle,
              ),
            ),
          ),
          Positioned(
            left: -20,
            bottom: -20,
            child: Container(
              width: 80,
              height: 80,
              decoration: BoxDecoration(
                color: Colors.white.withAlpha((0.1 * 255).round()),
                shape: BoxShape.circle,
              ),
            ),
          ),
          Center(
            child: Icon(
              Icons.campaign,
              color: Colors.white.withAlpha((0.3 * 255).round()),
              size: 60,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildQuickActionItem(
    IconData icon,
    String title,
    Color color,
    VoidCallback onTap,
  ) {
    return InkWell(
      onTap: onTap,
      borderRadius: BorderRadius.circular(12),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            width: 44,
            height: 44,
            decoration: BoxDecoration(
              color: color.withAlpha((0.1 * 255).round()),
              borderRadius: BorderRadius.circular(12),
            ),
            child: Icon(
              icon,
              color: color,
              size: 22,
            ),
          ),
          const SizedBox(height: 6),
          Flexible(
            child: Text(
              title,
              style: const TextStyle(
                fontSize: 11,
                color: Colors.black87,
                fontWeight: FontWeight.w500,
              ),
              textAlign: TextAlign.center,
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
            ),
          ),
        ],
      ),
    );
  }
}
